package com.zhiwang.planet.mvp.p

import com.zhiwang.planet.di.ActivityScope
import com.zhiwang.planet.mvp.v.VipView
import com.zhiwang.planet.mvvm.model.RestApi
import com.zhiwang.planet.util.androidSchedule
import com.zhiwang.planet.util.responseFunc
import com.uber.autodispose.AutoDispose.autoDisposable
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider
import com.zhiwang.planet.BuildConfig
import com.zhiwang.planet.util.AppHelper
import javax.inject.Inject

@ActivityScope
class VipPresenter @Inject constructor(var restApi: RestApi, var scopeProvider: AndroidLifecycleScopeProvider) {

    lateinit var vipView: VipView

    fun getVipInfo() {
        restApi.getVipInfo(vipUrl())
                .androidSchedule()
                .responseFunc()
                .`as`(autoDisposable(scopeProvider))
                .subscribe({
                    vipView.onLoadVipInfo(it)
                }, {
                    vipView.onError(it)
                }, {

                })

    }

    private fun vipUrl(): String {
        if (BuildConfig.DEBUG) {
            return if (AppHelper.testEnv())
                BuildConfig.DEBUG_Ji7_BASE_URL + "vip/xqvipindex"
            else BuildConfig.RELEASE_Ji7_BASE_URL + "vip/xqvipindex"
        }
        return BuildConfig.RELEASE_Ji7_BASE_URL + "vip/xqvipindex"
    }
}